import { loadStore } from '@/store'

export function isVip () {
  const userStore = loadStore()
  const { token, userInfo } = userStore
  // console.log('userStore token:', token)
  // console.log('userStore userInfo:', userInfo)
  // 会员到期时间
  if (token && userInfo && userInfo.role && userInfo.vipExpireDate) {
    let role = userInfo.role
    let noExpired = (new Date()) < (new Date(userInfo.vipExpireDate))
    if (role === 'admin') {
      return true
    } else if (role === 'vip' && noExpired) {
      return true
    } else {
      return false
    }

  } else {
    return false
  }
}

export function getRole () {
  const userStore = loadStore()
  const { userInfo } = userStore
  return userInfo && userInfo.role
}

export function isAdmin () {
  const userStore = loadStore()
  const { userInfo } = userStore

  return userInfo && userInfo.role === 'admin'
}
